package com.hb.game.pk.widgets.bottombar;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hb.game.pk.R;


public class AlphaTabView extends LinearLayout {
    private int iconSelectedId;
    private int iconNormalId;
    private int textColorSelected;
    private int textColorNormal;
    private TextView textView;
    private ImageView imageView;
    private Context mContext;
    private boolean isSelected = false;

    public AlphaTabView(Context context) {
        super(context, null);
        mContext = context;
        init(context, null);
    }

    public AlphaTabView(Context context, AttributeSet attrs) {
        super(context, attrs, 0);
        mContext = context;
        init(context, attrs);
    }

    public AlphaTabView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        setGravity(Gravity.CENTER);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        View inflate = View.inflate(context, R.layout.view_item_nav, this);
        imageView = (ImageView) inflate.findViewById(R.id.iv_item);
        textView = (TextView) inflate.findViewById(R.id.tv_item);
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AlphaTabView);

        float imageSize = a.getDimension(R.styleable.AlphaTabView_iconSize, 0);
        iconNormalId = a.getResourceId(R.styleable.AlphaTabView_tabIconNormal, 0);
        iconSelectedId = a.getResourceId(R.styleable.AlphaTabView_tabIconSelected, 0);
        imageView.setImageResource(iconNormalId);

        String tabText = a.getString(R.styleable.AlphaTabView_tabText);
        textColorNormal = a.getColor(R.styleable.AlphaTabView_textColorNormal, 0);
        textColorSelected = a.getColor(R.styleable.AlphaTabView_textColorSelected, 0);
        textView.setText(tabText);
        textView.setTextColor(textColorNormal);
    }


    public void setSelected(boolean tag) {
        isSelected = tag;
        if (tag) {
            imageView.setImageResource(iconSelectedId);
            textView.setTextColor(textColorSelected);
        } else {
            imageView.setImageResource(iconNormalId);
            textView.setTextColor(textColorNormal);
        }
    }
}
